/*
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.dspl.validate.violation;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.dspl.model.DataType;
import com.google.dspl.model.Identifier;
import com.google.dspl.validate.ItemReference;

import java.util.List;

/**
 * Violation for a concept attribute whose type conflicts with the concept containing the
 * value's type.
 *
 * @author Maryla Ustarroz Calonge
 */
public final class ConceptAttributeConflictingValueConceptTypeViolation extends Violation {

  private static final long serialVersionUID = -3025749856278141941L;

  private final String attributeId;
  private final String conceptId;
  private final DataType attributeType;
  private final Identifier valueConceptId;
  private final DataType valueConceptType;

  public ConceptAttributeConflictingValueConceptTypeViolation(
      ItemReference location,
      String attributeId,
      String conceptId,
      DataType attributeType,
      Identifier valueConceptId,
      DataType valueConceptType) {
    super(Severity.ERROR, location);
    this.attributeId = attributeId;
    this.conceptId = conceptId;
    this.attributeType = Preconditions.checkNotNull(attributeType);
    this.valueConceptId = Preconditions.checkNotNull(valueConceptId);
    this.valueConceptType = Preconditions.checkNotNull(valueConceptType);
  }

  @Override
  public List<Object> getDefaultTemplateParameters() {
    return ImmutableList.<Object>of(
        attributeId, conceptId, attributeType, valueConceptId, valueConceptType);
  }

  @Override
  public String getDefaultTemplate() {
    return "Attribute %s of concept %s has type %s, but the concept %s containing values for the "
        + "attribute has type %s";
  }

  public String getAttributeId() {
    return attributeId;
  }

  public String getConceptId() {
    return conceptId;
  }

  public DataType getAttributeType() {
    return attributeType;
  }

  public Identifier getValueConceptId() {
    return valueConceptId;
  }

  public DataType getValueConceptType() {
    return valueConceptType;
  }

  @Override
  public <T> T accept(ViolationVisitor<T> visitor) {
    return visitor.visit(this);
  }
}
